
<div class="eject_con">
  <div class="adds">
    <div id="warning"></div>
    <form method="post" action="{:url('member/address/modify')}" id="address_form" target="_parent">
      <input type="hidden" name="form_submit" value="ok" />
      <input type="hidden" name="id" value="{$address_info.address_id|default=''}" />
      <dl>
        <dt><i class="required">*</i>收货人：</dt>
        <dd>
          <input type="text" class="text w100" name="true_name" value="{$address_info.true_name|default=''}"/>
          <p class="hint">请填写您的真实姓名</p>
        </dd>
      </dl>
      <dl>
        <dt><i class="required">*</i>所在地区：</dt>
        <dd>
          <div id="region">
            <input type="hidden" value="{$address_info.city_id|default=0}" name="city_id" id="city_id">
            <input type="hidden" name="area_id" id="area_id" value="{$address_info.area_id|default=0}" class="area_ids" />
            <input type="hidden" name="area_info" id="area_info" value="{$address_info.area_info|default=''}" class="area_names" />
            {if(!empty($address_info['area_id']))}
            <span>{$address_info.area_info}</span>
            <input type="button" value="编辑" class="edit_region" />
            <select style="display:none;">
            </select>
            {else /}
            <select>
            </select>
            {/if}
         </div>
        </dd>
      </dl>
      <dl>
        <dt><i class="required">*</i>街道地址：</dt>
        <dd>
          <input class="text w300" type="text" name="address" value="{$address_info.address|default=''}"/>
          <p class="hint">不必重复填写地区</p>
        </dd>
      </dl>
      <dl>
        <dt><i class="required">*</i>电话号码：</dt>
        <dd>
          <input type="text" class="text w200" name="tel_phone" value="{$address_info.tel_phone|default=''}"/>
          <p class="hint">区号 - 电话号码 - 分机</p>
        </dd>
      </dl>
      <dl>
        <dt><i class="required">*</i>手机号码：</dt>
        <dd>
          <input type="text" class="text w200" name="mob_phone" value="{$address_info.mob_phone|default=''}"/>
        </dd>
      </dl>
            <dl>
        <dt><em class="pngFix"></em>设为默认地址：</dt>
        <dd>
          <input type="checkbox" {if(isset($address_info) && $address_info['is_default'] > 0)}checked {/if}class="checkbox vm mr5"  name="is_default" id="is_default" value="1" />
          <label for="is_default">设置为默认收货地址</label>
        </dd>
      </dl>
                  <div class="bottom">
        <label class="submit-border">
          <input type="submit" class="submit" value="新增地址" />
        </label>
        <a class="ncm-btn ml5" href="javascript:DialogManager.close('my_address_edit');">取消</a> </div>
    </form>
  </div>
</div>
<script type="text/javascript" src="/old/data/resource/js/common_select.js?v1.2" charset="utf-8"></script> 
<script type="text/javascript" src="/static/area/area.min.js?v=1.0"></script>
<script type="text/javascript">
var SITEURL = "{$Think.config.url_base}";
$(document).ready(function(){
	/* WYArea.init(function(){
		<?php if(isset($address_info) && !empty($address_info['area_id'])){ ?>
		WYArea.select({def:<?php echo $address_info['area_id'];?>, level: 3, prov:'#prov', city:'#city', area:'#area'});
		<?php }else{?>
		WYArea.select({def:0, level: 3, prov:'#prov', city:'#city', area:'#area'});
		<?php } ?>
	}); */
	regionInit("region");
    $('#address_form').validate({
    	submitHandler:function(form){
    		if ($('select[class="valid"]').eq(1).val()>0) $('#city_id').val($('select[class="valid"]').eq(1).val());
    		//$('#area_info').val($('#prov').find("option:selected").text() + $('#city').find("option:selected").text() + $('#area').find("option:selected").text());
    		ajaxpost('address_form', '', '', 'onerror');
    	},
        errorLabelContainer: $('#warning'),
        invalidHandler: function(form, validator) {
           var errors = validator.numberOfInvalids();
           if(errors)
           {
               $('#warning').show();
           }
           else
           {
               $('#warning').hide();
           }
        },
        rules : {
            true_name : {
                required : true
            },
            address : {
                required : true
            },
            tel_phone : {
                required : check_phone,
                minlength : 6,
				maxlength : 20
            },
            mob_phone : {
                required : check_phone,
                minlength : 11,
				maxlength : 11,                
                digits : true
            },
            prov : {
            	required : true,
            },
            city : {
            	required : true,
            },
            area : {
            	required : true,
            }
        },
        messages : {
            true_name : {
                required : '请填写收货人姓名'
            },
            address : {
                required : '请填写详细地址'
            },
            tel_phone : {
                required : '固定电话和手机请至少填写一项.',
                minlength: '电话号码由数字、加号、减号、空格、括号组成,并不能少于6位. ',
				maxlength: '电话号码由数字、加号、减号、空格、括号组成,并不能少于6位. '
            },
            mob_phone : {
                required : '固定电话和手机请至少填写一项.',
                minlength: '错误的手机号码',
				maxlength: '错误的手机号码',
                digits : '错误的手机号码'
            },
            prov : {
            	required : '<i class="icon-exclamation-sign"></i>请选择所在省',
            },
            city : {
            	required : '<i class="icon-exclamation-sign"></i>请选择所在市',
            },
            area : {
            	required : '<i class="icon-exclamation-sign"></i>请选择所在区',
            }
        },
        groups : {
            phone:'tel_phone mob_phone'
        }
    });
    $('#zt').on('click',function(){
    	DialogManager.close('my_address_edit');
    	ajax_form('daisou','使用代收货（自提）', 'index.php?act=member_address&op=delivery_add', '900',0);
    });
});
function check_phone(){
    return ($('input[name="tel_phone"]').val() == '' && $('input[name="mob_phone"]').val() == '');
}
</script>